package com.qf.service.impl;

import com.qf.exception.CustomerException;
import com.qf.mapper.MaterialMapper;
import com.qf.mapper.StorageMapper;
import com.qf.pojo.Material;
import com.qf.service.StorageService;
import com.qf.vo.StorageVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zdl
 * @date 2025/2/15
 */
@Service
public class StorageServiceImpl implements StorageService {
    @Resource
    private StorageMapper storageMapper;
    @Resource
    private MaterialMapper materialMapper;
    @Override
    public List<StorageVo> findAllStorage() {
        return storageMapper.selectAllStorage();
    }

    @Override
    public int delStorageBySid(int sid) {
        //先查询储物室是否含有物资
        Material material = materialMapper.selectMaterialBySid(sid);
        if (material != null){
            throw new CustomerException("90001","无法删除该房间，因为该房间存放了物资或设备");
        }
        return storageMapper.delStorage(sid);
    }
}
